package dialog;

import com.browniebytes.javafx.control.DateTimePicker;
import com.lanhai.model.SysError;

import application.Main;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
/**
 * 异常记录列表
 * @author liangmin
 *
 */
public class SysErrorListDialog {

/*	private static final Logger logger = Logger.getLogger(SysErrorListDialog.class);*/
	@FXML
	private Button search;
	@FXML
	private DateTimePicker beginTime;
	@FXML
	private DateTimePicker endTime;
	@FXML
	private TableView<SysError> error_list;
	public ObservableList<SysError> errData;
	
	public void init(Main main) {
		setListField();
		search.setOnAction((ActionEvent t) -> {
//    		String bstr = beginTime.dateTimeProperty().get().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//    		String estr = endTime.dateTimeProperty().get().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//    		String sql = "select * from sys_error where occurTime>'" + bstr + "' and occurTime<'" + estr + "'";
//    		ResultSet resultSet = DBConnection.executeQuery(sql);
//    		try{
//    			errData = FXCollections.observableArrayList();
//        		while(resultSet.next()){
//        			SysError se = new SysError();
//        			se.setId(resultSet.getInt("id"));
//        			se.setAgvId(resultSet.getInt("agvId"));
//        			se.setNote(resultSet.getString("note"));
//        			se.setOccurTimeStr(resultSet.getString("occurTime"));
//        			errData.add(se);
//        		}    			
//        		error_list.setItems(errData);
//    		}catch(Exception e){
//    			e.printStackTrace();
//    		}
		});
	}
	
	public void setListField(){
		TableColumn<SysError, Integer> col1 = new TableColumn<>("序号");
		col1.setCellValueFactory(new PropertyValueFactory<>("id"));
		col1.setPrefWidth(60);
		col1.setStyle("-fx-alignment:CENTER;");
		TableColumn<SysError, Integer> col2 = new TableColumn<>("AGV编号");
		col2.setCellValueFactory(new PropertyValueFactory<>("agvId"));
		col2.setPrefWidth(60);
		col2.setStyle("-fx-alignment:CENTER;");
		TableColumn<SysError, String> col3 = new TableColumn<>("说明");
		col3.setCellValueFactory(new PropertyValueFactory<>("note"));
		col3.setPrefWidth(250);
		//col3.setStyle("-fx-alignment:CENTER;");
		TableColumn<SysError, String> col4 = new TableColumn<>("发生时间");
		col4.setCellValueFactory(new PropertyValueFactory<>("occurTimeStr"));
		col4.setPrefWidth(150);
		col4.setStyle("-fx-alignment:CENTER;");	
		error_list.getColumns().add(col1);
		error_list.getColumns().add(col2);
		error_list.getColumns().add(col4);
		error_list.getColumns().add(col3);
		
	}
	
}
